<template>
  <div class="page-layout">
    <!-- 头部部分，当不是登录页面时显示 -->
    <Header v-if="!isLoginPage" class="Mainheader"></Header>
    
    <!-- 主体部分，包含左侧和右侧内容 -->
    <div class="main-content" :class="{ 'no-sidebar': isLoginPage }">
      <!-- 左侧页面内容（根据路由动态渲染） -->
      <div class="left-content">
        <router-view />
      </div>
      
      <!-- 右侧日历组件，仅当不是登录页面时显示 -->
      <div v-if="!isLoginPage" class="right-sidebar-wrapper">
        <div class="right-sidebar" v-show="isSidebarVisible">
          <Calendar class="calendar" />
          <div class="about">
            <div class="about-me">关于我们:</div>
            <div class="about-text">本平台由飞云智创工作室倾力打造，若阁下对本站内容有任何进一步的需求或建议，敬请与我们联络。</div>
            <div class="about-email">邮箱:3604831153@qq.com</div>
          </div>
        </div>
        <!-- 切换显示日历和关于部分的按钮 -->
        <div v-if="isMobile" class="toggle-sidebar" @click="toggleSidebar">
          {{ isSidebarVisible ? '收起日历' : '显示日历' }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Header from './components/Header.vue';
import Calendar from './components/Calendar.vue';

export default {
  components: {
    Header,
    Calendar,
  },
  data() {
    return {
      isSidebarVisible: true, // 控制日历和关于部分的显示
      isMobile: false, // 用于判断是否是移动设备
    };
  },
  computed: {
    isLoginPage() {
      // 判断当前路由是否为登录页面
      return this.$route.path === '/login-register';
    },
	isNotDisplayCalendar() {
      // 判断当前路由是否为登录页面或路线图页面
      return this.$route.path === '/login-register' || this.$route.path === '/route';
    }
  },
  mounted() {
    this.checkIfMobile();
    window.addEventListener('resize', this.checkIfMobile);
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.checkIfMobile);
  },
  methods: {
    checkIfMobile() {
      this.isMobile = window.innerWidth <= 768;
      if (this.isMobile && this.isSidebarVisible) {
        // 如果是移动设备且侧边栏已显示，默认收起
        this.isSidebarVisible = false;
      }
    },
    toggleSidebar() {
      this.isSidebarVisible = !this.isSidebarVisible;
    },
  },
};
</script>

<style scoped>
.page-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* 主体部分，当不是登录页面时包含左侧和右侧 */
.main-content {
  display: flex;
  flex: 1;
}

.main-content.no-sidebar {
  flex-direction: column;
}

.left-content {
  flex: 1;
}

/* 包裹右侧 sidebar 的容器，用于偏移 */
.right-sidebar-wrapper {
  position: relative;
  left: -100px;
}

.right-sidebar {
  width: 380px;
  padding: 0 5px 10px 0;
  position: -webkit-sticky;
  position: sticky;
  top: 0;
}

.calendar {
  width: 100%;
  height: auto;
  background-color: #ffffff;
  box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.25);
  border-radius: 30px;
  padding: 20px;
}

.about {
  width: 400px;
  height: auto;
  display: flex;
  flex-direction: column;
  padding: 15px 0 15px 20px;
  background: #ffffff;
  box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1), 0px 0.5px 5px rgba(0, 0, 0, 0.1);
  border-radius: 13px;
  justify-content: flex-start;
  align-items: center;
}

.about-me {
  font-family: 'Segoe UI';
  font-size: 24px;
  line-height: 16px;
  letter-spacing: 0.1em;
  color: #71c4ef;
  align-self: flex-start;
}

.about-text {
  width: 358px;
  margin-top: 10px;
  font-family: 'Segoe UI';
  font-size: 20px;
  line-height: 30px;
  color: rgba(112, 112, 112, 0.89);
}

.about-email {
  font-family: 'Segoe UI';
  font-size: 20px;
  line-height: 30px;
  color: rgba(112, 112, 112, 0.89);
  align-self: flex-end;
}

/* 当屏幕宽度小于768px时，隐藏日历和关于部分 */
@media (max-width: 768px) {
  .right-sidebar-wrapper {
    position: relative;
    left: 0;
  }

  .right-sidebar {
    width: 100%;
  }

  .toggle-sidebar {
    background-color: #4caf50;
    color: white;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    border-radius: 5px;
  }
}

</style>
